//
//  AppStorage.m
//  YYZB
//
//  Created by 顾悦 on 16/4/19.
//
//

#import "AppStorage.h"

static AppStorage *sharedObj = nil;

@interface AppStorage ()

@property (strong, nonatomic) NSMutableDictionary *dataStore;

@end

@implementation AppStorage

- (NSMutableDictionary *)dataStore {
    if (!_dataStore) {
        _dataStore = NSMutableDictionary.new;
    }
    
    return _dataStore;
}

+ (AppStorage *)sharedInstance {
    @synchronized (self) {
        if (sharedObj == nil) {
            sharedObj = [[self alloc] init];
        }
    }
    return sharedObj;
}

+ (instancetype)allocWithZone:(NSZone *)zone {
    @synchronized (self) {
        if (sharedObj == nil) {
            sharedObj = [super allocWithZone:zone];
            return sharedObj;
        }
    }
    return nil;
}

- (instancetype)copyWithZone:(NSZone *)zone {
    return self;
}

- (instancetype)init {
    @synchronized(self) {
        self = [super init];
        return self;
    }
}

- (void)setObject:(NSString *)o forKey:(NSString *)k {
    self.dataStore[k] = o ?: @"";
}

- (NSString *)getObjectForKey:(NSString *)k {
    return self.dataStore[k] ?: @"";
}

- (void)delObjectForKey:(NSString *)k {
    self.dataStore[k] = @"";
}

@end
